exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

// import BaseController from "../../framework/common/controller/BaseController";

exports.default = class extends think.BaseSocket {
    /**
    * 所有事件上报的统一接口
    */
    allEventReportAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            const obj = _this.post('userId,objName,ObjPosition,BGID,area_code,remarks,baidu_x,baidu_y,source,businesskey,group_code,parent_name,sub_name,type,img_push');
            obj.create_by = obj.userId || _this.getUser().userId;
            obj.create_date = new Date();
            obj.update_date = obj.create_date;
            obj.update_by = obj.create_by;
            obj.id = think.uuid('v1');
            // 移动端上传图片
            if (obj.img_push) {
                const picPath = obj.img_push.split(',');
                obj.picPath = picPath;
            }
            if (obj.area_code && obj.group_code) {
                obj.ObjCode = obj.area_code + obj.group_code;
            }
            // 如果web端有图片上传，则保存图片
            if (!think.isEmpty(_this.file())) {
                console.log('web有图片上传');
                _this.uploadFileAction(obj.id);
            }
            try {
                const result = yield _this.service('cms/EventService').addEvent(obj);
                const event = result.dataValues;
                const users = yield _this.getOnlineModuleByUser('jdsl');
                const body = _this.getSocketMsgBody(event);
                const msgBox = _this.getSocketMsgBody();
                msgBox.title = '有事件上报';
                msgBox.menuUrl = 'accept';
                msgBox.result.id = obj.id;
                if (!think.isEmpty(users)) {
                    _this.sendMsgByUserAction(msgBox, users, 'msg_box');
                    _this.sendMsgByUserAction(body, users, 'accept_screen');
                }
                return _this.successJson('上报成功');
            } catch (e) {
                return _this.errorJson('事件上报失败');
            }
        })();
    }
    getEventListAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const {
                pageSize,
                page
            } = _this2.post('pageSize,page');
            const eventService = _this2.service('cms/EventService');
            const userIds = yield _this2.getOnlineModuleByUser('jdsl');
            const res = yield eventService.getRealTimeEventList(userIds, pageSize, page);
            if (!res.error) {
                aj.result = res;
                return _this2.json(aj);
            }
            return _this2.json(res);
        })();
    }

    /**
    * 查询事件
    */
    queryEventAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const eventService = _this3.service('cms/EventService');
            const res = yield eventService.getEvent(_this3.post());
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }

            return _this3.json(aj);
        })();
    }

    newAddEventAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const eventService = _this4.service('cms/EventService');
            const res = yield eventService.getNewAddEvent(_this4.post());
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }

            return _this4.json(aj);
        })();
    }

    update_read_flagAction() {
        var _this5 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const eventService = _this5.service('cms/EventService');
            const res = yield eventService.update_read_flag(_this5.post());
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }

            return _this5.json(aj);
        })();
    }

    queryEventListAction() {
        var _this6 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const eventListService = _this6.service('cms/EventService');
            const data = _this6.post();

            // const RES = await eventListService.allEventList();
            // console.log('39',RES);
            const result = yield eventListService.eventList(data);

            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this6.json(aj);
        })();
    }

    queryAllEventListAction() {
        var _this7 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const eventListService = _this7.service('cms/EventService');
            const data = _this7.post();

            // const RES = await eventListService.allEventList();
            // console.log('39',RES);
            const result = yield eventListService.allEventList(data);

            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this7.json(aj);
        })();
    }

    queryOldEventListAction() {
        var _this8 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const eventListService = _this8.service('cms/EventService');
            const data = _this8.post();
            const result = yield eventListService.eventOldList(data);

            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this8.json(aj);
        })();
    }

    /**
    * 按条件查询事件列表
    */

    querySpecificAction() {
        var _this9 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const specificEventService = _this9.service('cms/EventService');
            const data = _this9.post();
            const result = yield specificEventService.specificEvent(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this9.json(aj);
        })();
    }

    queryAllSpecificAction() {
        var _this10 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const specificEventService = _this10.service('cms/EventService');
            const data = _this10.post();
            const result = yield specificEventService.allSpecificEvent(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this10.json(aj);
        })();
    }

    // 查询事件分类

    queryEventGroupAction() {
        var _this11 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();

            const parentEventService = _this11.service('cms/EventService');
            const data = _this11.get();
            const result = yield parentEventService.EventGroup(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this11.json(aj);
        })();
    }
    // 查询部件分类

    queryPartGroupAction() {
        var _this12 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();

            const parentEventService = _this12.service('cms/EventService');
            const data = _this12.get();
            const result = yield parentEventService.PartGroup(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this12.json(aj);
        })();
    }

    /**
    * 查询事件大类
    */

    queryParentEventAction() {
        var _this13 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();

            const parentEventService = _this13.service('cms/EventService');
            const data = _this13.get();
            const result = yield parentEventService.parentEvent(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this13.json(aj);
        })();
    }

    /**
    * 按事件大类id查询小类
    */
    queryChildrenEventAction() {
        var _this14 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const childrenEventService = _this14.service('cms/EventService');
            const data = _this14.post();
            const result = yield childrenEventService.childrenEvent(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this14.json(aj);
        })();
    }

    /**
    * 按部件大类id查询部件小类
    * @returns {*}
    * @private
    */

    queryPartChildrenAction() {
        var _this15 = this;

        return _asyncToGenerator(function* () {
            const data = _this15.post();
            try {
                const res = yield _this15.service('cms/EventService').partChildren(data);
                return _this15.successJson(res);
            } catch (error) {
                return _this15.errorJson('查询失败');
            }
        })();
    }

    /**
    * 获取事件来源类型
    */
    eventSourceTypeAction() {
        var _this16 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const sourceTypeService = _this16.service('cms/EventService');
            const data = _this16.get();
            const result = yield sourceTypeService.eventSource(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this16.json(aj);
        })();
    }

    /**
    * 从字典表获取事件状态类型
    */
    eventStateTypeAction() {
        var _this17 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const stateTypeService = _this17.service('cms/EventService');
            const data = _this17.get();
            const result = yield stateTypeService.eventState(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this17.json(aj);
        })();
    }

    /**
    * 添加所属单元格id:BGID
    */

    addEventBGIDAction() {
        var _this18 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const BGIDService = _this18.service('cms/EventService');
            const res = yield BGIDService.eventBGID(_this18.post());
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '保存失败';
            }

            return _this18.json(aj);
        })();
    }

    // /**
    //  * 修改所属单元格id:BGID
    //  */
    //
    // async updateEventBGIDAction(){
    //     let aj = think.ajaxJson();
    //     const updateBGIDService = this.service('cms/EventService');
    //     const res = await updateBGIDService.updateEventBGID(this.post());
    //
    //     if(!res.error){
    //         aj.result = res
    //
    //     }else{
    //         aj.success = false;
    //         aj.msg = '保存失败'
    //     }
    //     return this.json(aj)
    // }

    /**
    * 事件废弃
    */
    eventDoneAction() {
        var _this19 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this19.post();
            const eventDoneService = _this19.service('cms/EventService');
            const res = yield eventDoneService.eventDone(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '操作失败';
            }

            return _this19.json(aj);
        })();
    }

    /**
    * 删除事件
    */

    deleteEventAction() {
        var _this20 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this20.post();
            const eventDoneService = _this20.service('cms/EventService');
            const res = yield eventDoneService.deleteEvent(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '操作失败';
            }

            return _this20.json(aj);
        })();
    }

    /**
    * 事件上报图片
    */
    eventPicAction() {
        var _this21 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this21.post();
            const eventPicService = _this21.service('cms/EventService');
            const res = yield eventPicService.eventPic(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '操作失败';
            }
            return _this21.json(aj);
        })();
    }

    /**
    * 查询事件状态by_id
    * @returns {Promise<*>}
    */
    queryEventStatusAction() {
        var _this22 = this;

        return _asyncToGenerator(function* () {
            const data = _this22.post();
            try {
                const res = yield _this22.service('cms/EventService').eventStatus(data);
                return _this22.successJson(res);
            } catch (error) {
                return _this22.errorJson('查询失败');
            }
        })();
    }
};